(function($) {
	$.notice = {
		show: function(message) {
			/** Configuration */
			var bottom = 15;
			var right = 15;
			var fadeoutDuration = 1000;
			
			/** Launch the notification */
			$('<div></div>').attr('id', 'notice').css('right', (0+right)+'px').css('top', (0+bottom)+'px').appendTo('body').text(message)
				.append('<span class="ui-icon ui-icon-info"></span>');
			
			/** Switch off the notification */
			setTimeout(function() {$('#notice').animate({ opacity: 0, top: '-20px' }, fadeoutDuration);}, 7000);
			setTimeout(function() {$('#notice').remove();}, 9000);
		}
	}
	
	jQnotice = function(message) { $.notice.show(message); };
})(jQuery);


/*

 *	faded 0.3.1 - jQuery plugin

 *	written by Nathan Searles	

 *	http://nathansearles.com/faded/

 *

 *	Copyright (c) 2009 Nathan Searles (http://nathansearles.com/)

 *	Dual licensed under the MIT (MIT-LICENSE.txt)

 *	and GPL (GPL-LICENSE.txt) licenses.

 *

 *	Built for jQuery library

 *	http://jquery.com

 *	Compatible with jQuery 1.3.2+

 *

 */

if(typeof jQuery != "undefined") {

	jQuery(function($) {

		$.fn.extend({

			faded: function(options) {

				var settings = $.extend({}, $.fn.faded.defaults, options);

				return this.each(

					function() {

						if($.fn.jquery < "1.3.1") {return;}

						var $t = $(this);

						var $c = $t.children(":nth-child(1)");

						var o = $.metadata ? $.extend({}, settings, $t.metadata()) : settings;

						var total = $c.children().size();

						var next = 0, prev = 0, number = 0, currentitem = 0, restart = 0, restartinterval = 0;

						var loaded,active,imgSrc,clicked,current;

						if (o.random) {

							$.fn.reorder = function(callback) {

								function randOrd() { return(Math.round(Math.random())-0.5); }

									return($(this).each(function() {

									var $this = $(this);

									var $children = $this.children();

									var childCount = $children.length;

									if (childCount > 1) {

										$children.hide();

										var indices = new Array();

										for (i=0;i<childCount;i++) { indices[indices.length] = i; }

										indices = indices.sort(randOrd);

										$.each(indices,function(j,k) { 

											var $child = $children.eq(k);

											var $clone = $child.clone(true);

											$clone.show().appendTo($this);

											if (callback !== undefined) {

												callback($child, $clone);

											}

										$child.remove();

									});

									}

								}));

							};

							$c.reorder();

						}

						function pause() {

							clearInterval(autoplay);

							clearTimeout(restart);

							restart = setTimeout(function() {

								autoplay = setInterval(function(){

									animate("next");

								},o.autoplay);

							},o.autorestart);			

						}				

						$c.css({position:"relative"});			

						$c.children().css({

							position:"absolute",

							top: 0, 

							left: 0,

							zIndex: 0,

							display:"none"

						 });

						if (o.autoheight) {

							$c.animate({height: $c.children(":eq(0)").outerHeight()},o.autoheight);

						}

						if (o.pagination) {

							if (o.autopagination) {

								$t.append("<ul class="+o.pagination+"></ul>");

								$c.children().each(function(){

									$("."+o.pagination+"",$t).append("<li><a rel="+number+" href=\"#\" >"+(number+1)+"</a></li>");

									number++;

								});

							}

							$("."+o.pagination+" li a:eq(0)",$t).parent().addClass("current");

							$("."+o.pagination+" li a",$t).click(function(){

								current = $("."+o.pagination+" li.current a",$t).attr("rel");									

								clicked = $(this).attr("rel");

								if (current != clicked) {animate("pagination",clicked,current);}

								if(o.autoplay){pause();}

								return false;

							});

						}

						if (o.sequentialloading&&$c.children()[0].tagName=="IMG") {

							$c.css({background:"url("+o.loadingimg+") no-repeat 50% 50%"});

							imgSrc = $("img:eq(0)",$c).attr("src");

							$("img:eq(0)",$c).attr("src", imgSrc).load(function() {

								$(this).fadeIn(o.speed,function(){

									loaded = true;

								});

							});

						} else {

							$c.find(":eq(0)").fadeIn(o.speed,function(){

								loaded = true;

							});

						}

						if (o.bigtarget) {

							$c.css({"cursor":"pointer"});

							$c.click(function(){

								animate("next");

								if(o.autoplay){

									if (o.autorestart) {

										pause();

									} else {

										clearInterval(autoplay);	

									}

								}

								return false;

							});									

						}			

						if (o.autoplay) {

							autoplay = setInterval(function(){

								animate("next");

							},o.autoplay);

							pause();

						}

						$("."+o.nextbtn,$t).click(function(){



							animate("next");

							if(o.autoplay){

								if (o.autorestart) {

									pause();

								} else {

									clearInterval(autoplay);	

								}

							}

							return false;

						});					

						$("."+o.prevbtn,$t).click(function(){

							animate("prev");

							if(o.autoplay){

								if (o.autorestart) {

									pause();

								} else {

									clearInterval(autoplay);	

							}

							}
							return false;
						});
						function animate(dir,clicked,current){
							if (!active&&loaded) {
								active=true;
								switch(dir) {
									case "next":
										prev = next;
										next = currentitem*1+1;
										if (total === next) { next = 0; }
									break;
									case "prev":
										prev = next;
										next = currentitem*1-1;
										if (next === -1) { next = total-1; }
									break;
									case "pagination":
										next = clicked;
										prev = current;
									break;
								}
								if (o.pagination) {
									$(".pagination li.current",$t).removeClass("current");
									$(".pagination li a:eq("+next+")",$t).parent().addClass("current");
								}
								if (o.crossfade) {
									$c.children(":eq("+next+")").css({zIndex:10}).fadeIn(o.speed,function(){
										$c.children(":eq("+prev+")").css({display:"none",zIndex:0});
										$(this).css({zIndex:0});
										currentitem = next;
										active = false;
									});
								} else {
									$c.children(":eq("+prev+")").fadeOut(o.speed,function(){
										if (o.autoheight) {
											$c.animate({height: $c.children(":eq("+next+")").outerHeight()},o.autoheight,function(){
												$c.children(":eq("+next+")").fadeIn(o.speed);
											});
										} else {
											$c.children(":eq("+next+")").fadeIn(o.speed);
										}
										currentitem = next;

										active = false;
									});
								}
							}
						}
					}
				);
				}
		});
		$.fn.faded.defaults = {
			speed: 300,
			crossfade: false,
			bigtarget: false,
			sequentialloading: false,
			autoheight: false,
			pagination: "pagination",
			autopagination: true,
			nextbtn: "next",
			prevbtn: "prev",
			loadingimg: false,
			autoplay: false,
			autorestart: false,
			random: false
		};
	});
}

jQuery.preloadCssImages = function(settings){

	settings = jQuery.extend({

		statusTextEl: null,

		statusBarEl: null,

		errorDelay: 999, // handles 404-Errors in IE

		simultaneousCacheLoading: 2

	}, settings);

	var allImgs = [],

		loaded = 0,

		imgUrls = [],

		thisSheetRules,	

		errorTimer;

	

	function onImgComplete(){

		clearTimeout(errorTimer);

		if (imgUrls && imgUrls.length && imgUrls[loaded]) {

			loaded++;	

			if (!(imgUrls[loaded])) {

				$('#loading-all').fadeOut('fast').remove();

			}

			/*if (settings.statusTextEl) {

				var nowloading = (imgUrls[loaded]) ? 

					'Now Loading: <span>' + imgUrls[loaded].split('/')[imgUrls[loaded].split('/').length - 1] : 

					'Loading complete'; // wrong status-text bug fixed

				jQuery(settings.statusTextEl).html('<span class="numLoaded">' + loaded + '</span> of <span class="numTotal">' + imgUrls.length + '</span> loaded (<span class="percentLoaded">' + (loaded / imgUrls.length * 100).toFixed(0) + '%</span>) <span class="currentImg">' + nowloading + '</span></span>');

			}

			if (settings.statusBarEl) {

				var barWidth = jQuery(settings.statusBarEl).width();

				jQuery(settings.statusBarEl).css('background-position', -(barWidth - (barWidth * loaded / imgUrls.length).toFixed(0)) + 'px 50%');

			}*/

			loadImgs();

		}

	}

	

	function loadImgs(){

		//only load 1 image at the same time / most browsers can only handle 2 http requests, 1 should remain for user-interaction (Ajax, other images, normal page requests...)

		// otherwise set simultaneousCacheLoading to a higher number for simultaneous downloads

		if(imgUrls && imgUrls.length && imgUrls[loaded]){

			var img = new Image(); //new img obj

			img.src = imgUrls[loaded];	//set src either absolute or rel to css dir

			if(!img.complete){

				jQuery(img).bind('error load onreadystatechange', onImgComplete);

			} else {

				onImgComplete();

			}

			errorTimer = setTimeout(onImgComplete, settings.errorDelay); // handles 404-Errors in IE

		}

	}

	

	function parseCSS(sheets, urls) {

		var w3cImport = false,

			imported = [],

			importedSrc = [],

			baseURL;

		var sheetIndex = sheets.length;

		while(sheetIndex--){//loop through each stylesheet

			

			var cssPile = '';//create large string of all css rules in sheet

			

			if(urls && urls[sheetIndex]){

				baseURL = urls[sheetIndex];

			} else {

				var csshref = (sheets[sheetIndex].href) ? sheets[sheetIndex].href : 'window.location.href';

				var baseURLarr = csshref.split('/');//split href at / to make array

				baseURLarr.pop();//remove file path from baseURL array

				baseURL = baseURLarr.join('/');//create base url for the images in this sheet (css file's dir)

				if (baseURL) {

					baseURL += '/'; //tack on a / if needed

				}

			}

			if(sheets[sheetIndex].cssRules || sheets[sheetIndex].rules){

				thisSheetRules = (sheets[sheetIndex].cssRules) ? //->>> http://www.quirksmode.org/dom/w3c_css.html

					sheets[sheetIndex].cssRules : //w3

					sheets[sheetIndex].rules; //ie 

				var ruleIndex = thisSheetRules.length;

				while(ruleIndex--){

					if(thisSheetRules[ruleIndex].style && thisSheetRules[ruleIndex].style.cssText){

						var text = thisSheetRules[ruleIndex].style.cssText;

						if(text.toLowerCase().indexOf('url') != -1){ // only add rules to the string if you can assume, to find an image, speed improvement

							cssPile += text; // thisSheetRules[ruleIndex].style.cssText instead of thisSheetRules[ruleIndex].cssText is a huge speed improvement

						}

					} else if(thisSheetRules[ruleIndex].styleSheet) {

						imported.push(thisSheetRules[ruleIndex].styleSheet);

						w3cImport = true;

					}

					

				}

			}

			//parse cssPile for image urls

			var tmpImage = cssPile.match(/[^\("]+\.(gif|jpg|jpeg|png)/g);//reg ex to get a string of between a "(" and a ".filename" / '"' for opera-bugfix

			if(tmpImage){

				var i = tmpImage.length;

				while(i--){ // handle baseUrl here for multiple stylesheets in different folders bug

					var imgSrc = (tmpImage[i].charAt(0) == '/' || tmpImage[i].match('://')) ? // protocol-bug fixed

						tmpImage[i] : 

						baseURL + tmpImage[i];

					

					if(jQuery.inArray(imgSrc, imgUrls) == -1){

						imgUrls.push(imgSrc);

					}

				}

			}

			

			if(!w3cImport && sheets[sheetIndex].imports && sheets[sheetIndex].imports.length) {

				for(var iImport = 0, importLen = sheets[sheetIndex].imports.length; iImport < importLen; iImport++){

					var iHref = sheets[sheetIndex].imports[iImport].href;

					iHref = iHref.split('/');

					iHref.pop();

					iHref = iHref.join('/');

					if (iHref) {

						iHref += '/'; //tack on a / if needed

					}

					var iSrc = (iHref.charAt(0) == '/' || iHref.match('://')) ? // protocol-bug fixed

						iHref : 

						baseURL + iHref;

					

					importedSrc.push(iSrc);

					imported.push(sheets[sheetIndex].imports[iImport]);

				}

				

				

			}

		}//loop

		if(imported.length){

			parseCSS(imported, importedSrc);

			return false;

		}

		var downloads = settings.simultaneousCacheLoading;

		while( downloads--){

			setTimeout(loadImgs, downloads);

		}

	}

	parseCSS(document.styleSheets);



	return imgUrls;

};

/*
 * jQuery doTimeout: Like setTimeout, but better! - v1.0 - 3/3/2010
 * http://benalman.com/projects/jquery-dotimeout-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($){var a={},c="doTimeout",d=Array.prototype.slice;$[c]=function(){return b.apply(window,[0].concat(d.call(arguments)))};$.fn[c]=function(){var f=d.call(arguments),e=b.apply(this,[c+f[0]].concat(f));return typeof f[0]==="number"||typeof f[1]==="number"?this:e};function b(l){var m=this,h,k={},g=l?$.fn:$,n=arguments,i=4,f=n[1],j=n[2],p=n[3];if(typeof f!=="string"){i--;f=l=0;j=n[1];p=n[2]}if(l){h=m.eq(0);h.data(l,k=h.data(l)||{})}else{if(f){k=a[f]||(a[f]={})}}k.id&&clearTimeout(k.id);delete k.id;function e(){if(l){h.removeData(l)}else{if(f){delete a[f]}}}function o(){k.id=setTimeout(function(){k.fn()},j)}if(p){k.fn=function(q){if(typeof p==="string"){p=g[p]}p.apply(m,d.call(n,i))===true&&!q?o():e()};o()}else{if(k.fn){j===undefined?e():k.fn(j===false);return true}else{e()}}}})(jQuery);